from django.db import models
from utils.modelsMixin import ModelSetMixin
from django.contrib.auth.models import User  # auth自带的用户表

# Create your models here.

# 标签模型类
class Label(models.Model):
    name = models.CharField(max_length=30, verbose_name='标签名',unique=True)
    # 一对多联系，一个用户可以查看多个阶段的题目进行学习
    user = models.ForeignKey(User,on_delete=models.CASCADE)

    class Meta:
        db_table = 'label'  # 设置表名
        verbose_name = '标签'
        verbose_name_plural = verbose_name

    # 定义数据返回的类型
    def __str__(self):
        return self.name

# 题目类
class Topic(ModelSetMixin):
    TYPE_CHOICES = (
        (0,'单选题'),
        (1,'多选题'),
        (2,'判断题'),
        (3,'填空题'),
        (4,'问答题'),
    )
    subject = models.TextField(verbose_name='题干')  # 长文本类型
    type = models.IntegerField(verbose_name='类型',choices=TYPE_CHOICES)
    score = models.FloatField(verbose_name='分值',default=1.0,null=True,blank=True)
    description = models.TextField(verbose_name='题目描述',null=True,blank=True)  # 长文本类型
    answer = models.TextField(verbose_name='答案')
    # 那个阶段的题目，打上标签
    label = models.ForeignKey(Label,on_delete=models.CASCADE)
    # 哪个用户出的题目
    user = models.ForeignKey(User,on_delete=models.CASCADE)

    class Meta:
        ordering = ['-update_time']   # 排序
        db_table = 'topic'  # 设置表名
        verbose_name = '题目'
        verbose_name_plural = verbose_name


